import * as request from "request"
import { User } from "./User"
import { Repo } from "./Repo"


const options = {
    headers: {
        "User-Agent": "request"
    },
    json: true
}

export class GiteeApiService {
    getUserInfo(username: string, callback: any) {
        request.get("https://gitee.com/api/v5/users/" + username, options, (error: any, response: any, body: any) => {
            console.log(typeof body);
            let user: User = new User(body);
            callback(user);
        })
    }

    getUserRepos(username: string, callback: any) {
        request.get("https://gitee.com/api/v5/users/" + username + "/repos", options, (error: any, response: any, body: any) => {
            // let repos: Repo[] = body.map((item: any) => {
            //     return new Repo(item)
            // });
            let repos: Repo = new Repo(body);
            callback(repos.array);
        })
    }
}

